import createDOMElement from "./createDOMElement";
import unmountNode from "./unmountNode";
export default function mountNativeElement(virtualDOM,container,oldDOM){
    let newElement = createDOMElement(virtualDOM)
    if(oldDOM){
        // 需要插入到当前oldDOM的前面
        container.insertBefore(newElement,oldDOM)
    } else {
        // 将转化后的DOM对象放置在页面中
        container.appendChild(newElement)
    }
    // 当旧的DOM对象存在 需要删除 oldDOM
    if(oldDOM){
        unmountNode(oldDOM)
    }

    let component = virtualDOM.component
    if(component){
        // 只有类组件上会有setDOM方法
        component.setDOM(newElement)
    }
}